package com.yanggu.mapreduce.nlineInputformat;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2019/12/15 11:28
 * @description:
 */
public class NLineInputFormatReducer extends Reducer<Text, LongWritable, Text, LongWritable> {

    private LongWritable v = new LongWritable();


    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        //1. 累加求和
        long sum = 0;
        for (LongWritable value : values) {
            sum += value.get();
        }

        //2. 写出
        v.set(sum);
        context.write(key, v);
    }
}
